package in.iqing.view.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.OnClick;
import in.iqing.app.R;
import in.iqing.base.BaseFragment;
import in.iqing.control.helper.IntentHelper;
import in.iqing.model.sp.AccountSP;
import in.iqing.view.activity.AboutActivity;
import in.iqing.view.activity.DownloadListActivity;
import in.iqing.view.activity.HistoryActivity;
import in.iqing.view.activity.LoginActivity;
import in.iqing.view.activity.SubscribeBookListActivity;
import in.iqing.view.activity.UserActivity;

/**
 * Created by ZuoShu on 15/7/3.
 */
public class MyStatusFragment extends BaseFragment {
    @Bind(R.id.username)
    TextView username;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_my_status, null);
    }

    @Override
    protected void onInitialize(Bundle savedInstanceState) {
        super.onInitialize(savedInstanceState);
    }

    @Override
    public void onResume() {
        super.onResume();
        refreshUserStatus();
    }

    private void refreshUserStatus() {
        if (AccountSP.isLogin()) {
            username.setText(AccountSP.getUserName());
        } else {
            username.setText(R.string.fragment_my_status_login_label);
        }
    }

    @OnClick(R.id.avatar_layout)
    public void onAvatarLayoutClick(View v) {
        if (AccountSP.isLogin()) {
            IntentHelper.startActivity(getActivity(), UserActivity.class);
        } else {
            IntentHelper.startActivity(getActivity(), LoginActivity.class);
        }
    }

    @OnClick(R.id.subscribe_layout)
    public void onSubscribeClick(View v) {
        IntentHelper.startActivity(getActivity(), SubscribeBookListActivity.class);
    }

    @OnClick(R.id.history_layout)
    public void onHistoryClick(View v) {
        IntentHelper.startActivity(getActivity(), HistoryActivity.class);
    }

    @OnClick(R.id.submit_layout)
    public void onSubmitClick(View v) {
    }

    @OnClick(R.id.about_layout)
    public void onAboutClick(View v) {
        IntentHelper.startActivity(getActivity(), AboutActivity.class);
    }

    @OnClick(R.id.cache_layout)
    public void onCacheClick(View v) {
        IntentHelper.startActivity(getActivity(), DownloadListActivity.class);
    }
}
